import utils from "@/libs/utils";

export const group = "Home";

export const model = {
  BOOT_PAGE: {},
  BANNER_LIST: {},
  HB_POOL_LOG_LIST: {},
  INDEX_MISSION: {},
  INDEX_DATA: {},
  HB_POOL_LOG_LIST_Page: {},
  SEVENDAY_HB_POOL_LOG_LIST: []
};

export const types = utils.genTypes(model, group);
export const state = utils.genState(model, group);
export const getters = utils.genGetters(types);
export const mutations = utils.genMutations(types);

const apis = {
  BOOT_PAGE: () => "/index/queryBootPage",
  /* done */ BANNER_LIST: () => "/index/queryBannerList",
  HB_POOL_LOG_LIST: () => "/index/queryHbPoolLogList",
  /* done */ INDEX_MISSION: () => "/index/queryIndexMission",
  INDEX_DATA: () => "/index/queryIndexData",
  HB_POOL_LOG_LIST_Page: () => "/index/queryHbPoolLogListByPage",
  SEVENDAY_HB_POOL_LOG_LIST: () => "/index/querySevenDayHbPoolLogList"
};

const gens = {
  /**
   * 查询app启动页列表
   */
  BOOT_PAGE: utils.genAction("BOOT_PAGE", types, model),
  /**
   * 查询banner列表
   */
  BANNER_LIST: utils.genAction("BANNER_LIST", types, model),
  /**
   * 查询红包走势列表
   * pageNo
   * pageSize
   */
  HB_POOL_LOG_LIST: utils.genAction("HB_POOL_LOG_LIST", types, model),
  /**
   * 查询首页推荐任务
   */
  INDEX_MISSION: utils.genAction("INDEX_MISSION", types, model),
  /**
   * 查询首页统计数据
   */
  INDEX_DATA: utils.genAction("INDEX_DATA", types, model),
  /**
   * 查询红包涨幅列表
   */
  HB_POOL_LOG_LIST_Page: utils.genAction("HB_POOL_LOG_LIST_Page", types, model),
  /**
   * 查询7日红包走势列表
   */
  SEVENDAY_HB_POOL_LOG_LIST: utils.genAction(
    "SEVENDAY_HB_POOL_LOG_LIST",
    types,
    model
  )
};

const options = {
  BANNER_LIST: {
    transform: t => {
      return {
        list: t.data
      };
    }
  },
  INDEX_MISSION: {
    transform: t => {
      return {
        list: t.data
      };
    }
  },
  HB_POOL_LOG_LIST: {
    transform: utils.listTransform
  }
};

export const actions = utils.genActions(types, apis, gens, options);

export default { state, getters, mutations, actions };
